package com.foton.logistic.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.foton.logistic.R;
import com.foton.logistic.listener.IOnShopClickListener;
import com.foton.logistic.model.ShopResult;
import com.foton.logistic.view.ultimate.UltimateViewAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by wuhaocong on 2017/9/14.
 */

public class ShopAdapter extends UltimateViewAdapter {
    public Context context;
    public List<ShopResult.DataEntity> list = new ArrayList<>();
    private IOnShopClickListener iOnShopClickListener;
    private ShopResult.DataEntity dataEntity;
    public ShopAdapter(Context context, List<ShopResult.DataEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        View v = null;
        RecyclerView.ViewHolder holer = null;
        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.ft_adapter_shop, null);
        v.setLayoutParams(layoutParams);
        holer = new ShopAdapter.MyViewHolder(v);
        return holer;
    }
    public void setiOnShopClickListener(IOnShopClickListener iOnShopClickListener) {
        this.iOnShopClickListener = iOnShopClickListener;
    }
    @Override
    public int getAdapterItemCount() {
        return list.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (position < getItemCount() && (customHeaderView != null ? position <= list.size() : position < list.size()) && (customHeaderView != null ? position > 0 : true)) {
            ShopAdapter.MyViewHolder viewHolder = (ShopAdapter.MyViewHolder) holder;
            dataEntity = list.get(position);
            viewHolder.name.setText(dataEntity.carrierName);
            viewHolder.time.setText(dataEntity.applyTime);
            viewHolder.num.setText(dataEntity.carrierNum);
            if ("1".equals(dataEntity.carrierType)){
                viewHolder.alipayLayout.setVisibility(View.VISIBLE);
                viewHolder.status.setText("待处理");
            }else if ("2".equals(dataEntity.carrierType)){
                viewHolder.alipayLayout.setVisibility(View.GONE);
                viewHolder.status.setText("成功");
            }else if ("3".equals(dataEntity.carrierType)){
                viewHolder.alipayLayout.setVisibility(View.GONE);
                viewHolder.status.setText("失败");
            }else if ("4".equals(dataEntity.carrierType)){
                viewHolder.alipayLayout.setVisibility(View.GONE);
                viewHolder.status.setText("失败(后台审核不通过)");
            }else if ("5".equals(dataEntity.carrierType)){
                viewHolder.alipayLayout.setVisibility(View.GONE);
                viewHolder.status.setText("待审核");
            }else {
                viewHolder.alipayLayout.setVisibility(View.GONE);
                viewHolder.status.setText("成功");
            }
            viewHolder.pass.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (iOnShopClickListener != null) {
                        iOnShopClickListener.onPassClick(position);
                    }
                }
            });
            viewHolder.reject.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (iOnShopClickListener != null) {
                        iOnShopClickListener.onRejectClick(position);
                    }
                }
            });
        }

    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.ft_ui_adapter_order_name)
        TextView name;
        @InjectView(R.id.ft_ui_adapter_order_num)
        TextView num;
        @InjectView(R.id.ft_ui_adapter_order_time)
        TextView time;
        @InjectView(R.id.ft_ui_adapter_status)
        TextView status;
        @InjectView(R.id.ft_ui_adapter_order_btn_layout)
        LinearLayout alipayLayout;
        @InjectView(R.id.ft_ui_adapter_pass)
        TextView pass;
        @InjectView(R.id.ft_ui_adapter_reject)
        TextView reject;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

}
